package com.yunjie.action.user;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;
import com.yunjie.action.BaseAction;
import com.yunjie.model.UserInfo;
import com.yunjie.service.user.UserService;
@Scope("prototype")
@Controller("userAction")
public class UserAction extends BaseAction implements ModelDriven<UserInfo> {
	private static final long serialVersionUID = -445124133197526382L;
	private UserInfo user = new UserInfo();
	private Map<String, Object> msg = new HashMap<String, Object>();
	@Autowired
	private UserService userService;
	
	public UserInfo getUser() {
		return user;
	}

	public Map<String, Object> getMsg() {
		return msg;
	}

	public void setMsg(Map<String, Object> msg) {
		this.msg = msg;
	}

	public void setUser(UserInfo user) {
		this.user = user;
	}

	@Override
	public UserInfo getModel() {
		// TODO Auto-generated method stub
		return this.user;
	}
	public String login() throws Exception {
		user = userService.login(user);
		msg.put("user", user);
		return SUCCESS;
	}
	public String save() throws Exception {
		user = userService.saveAndUpdata(user);
		msg.put("success", "true");
		msg.put("msg", "success");
		return SUCCESS;
	}
	public String list() throws Exception {
		List<UserInfo> userList = userService.findAll(-1, -1);
		msg.put("users", userList);
		return SUCCESS;
	}
}
